package com.eliysha.bible;

import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.os.Bundle;
import android.view.View;

public class Main extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(new MYGIFView(this));
		// setContentView(R.layout.splash);

		Thread welcomeThread = new Thread() {

			//int wait = 0;

			@Override
			public void run() {
				try {
					super.run();
					Bible maBible = new Bible();
					maBible.initialize(Main.this);
					/**
					 * use while to get the splash time. Use sleep() to increase
					 * the wait variable for every 100L.
					 *
					while (wait < welcomeScreenDisplay) {
						sleep(100);
						wait += 100;
					}*/
				} catch (Exception e) {
					System.out.println("EXc=" + e);
				} finally {
					/**
					 * Called after splash times up. Do some action after splash
					 * times up. Here we moved to another main activity class
					 */
					startActivity(new Intent(Main.this, Home.class));
					finish();
				}
			}
		};
		welcomeThread.start();

	}

}

class MYGIFView extends View {

	Movie movie, movie1;
	InputStream is = null, is1 = null;
	long moviestart;

	public MYGIFView(Context context) {
		super(context);
		is = context.getResources().openRawResource(R.drawable.ajax_loader);
		movie = Movie.decodeStream(is);

	}

	@Override
	protected void onDraw(Canvas canvas) {

		canvas.drawColor(Color.WHITE);
		super.onDraw(canvas);
		long now = android.os.SystemClock.uptimeMillis();
		System.out.println("now=" + now);
		if (moviestart == 0) { // first time
			moviestart = now;
		}
		
		System.out.println("\tmoviestart=" + moviestart);
		int relTime = (int) ((now - moviestart) % movie.duration());
		System.out.println("time=" + relTime + "\treltime=" + movie.duration());
		movie.setTime(relTime);
		movie.draw(canvas, this.getWidth() / 2 - 20, this.getHeight() / 2 - 40);
		this.invalidate();
	}
}